<?php
/**
 * 存储临时数据
 * 
 * 制作:  叶风
 * Qq:    355007778
 * Email: ye.fn@163.com
 *
 */

namespace c\temp;

class db extends \control
{
    var $table = 'temp';
    /**
	 * 
	 * @param type $mark  为避免冲突，名称以 cont 开头
	 * @param type $v
	 * @return type
	 */
    function save($mark, $v)
    {	
        $d = array('mark'=>$mark, 'val'=>$v, 'create_time'=>UNIX_TIME);

        $w = "`mark`='$mark'";
		if (!$this->db->getOne($this->table, '*', $w))
            $w = '';
        return $this->db->save($this->table, $d, $w);
    }
    function findVal($mark)
    {
        $mark = $this->db->escape($mark);
        return $this->db->getOneField($this->table, 'val', "`mark`='$mark'");
    }
    function findRow($mark)
    {
        $mark = $this->db->escape($mark);
        return $this->db->getOne($this->table, '*', "`mark`='$mark'");
    }
    function del($mark)
    {
        $mark = $this->db->escape($mark);
        return $this->db->del($this->table, "`mark`='$mark'");
    }
	function find_del($mark)
    {
        $a = $this->findRow($mark);
		if ($a)
			$this->del($mark);
		return $a;
    }
    /**
     * 清除30天以前
     */
    function cl()
    {
    	$ti = UNIX_TIME - 86400 * 30;
    	$this->db->del($this->table,"`create_time` < '$ti'");
    }
}   